const arr = [1, 3, 5, 2, 4, 6]
const data = [
  {
    part: 1,
    locations: [1, 2, 3]
  },
  {
    part: 2,
    locations: [3, 6]
  },
  {
    part: 3,
    locations: [4]
  },
  {
    part: 4,
    locations: [2]
  },
  {
    part: 5,
    locations: [3, 5]
  }
]
const getCircle = (arr) => {
  let newArr = [...arr]
  let reduceArr = []
  const resArr = []
  let curCircle = 1

  while (newArr.length) {
    const target = newArr.shift()
    const reduceLocations = reduceArr.reduce((prev, item) => {
      prev.push(...item.locations)
      return prev
    }, [])
    const newLocations = reduceArr.reduce((prev, item) => {
      prev.push(...item.locations)
      return prev
    }, [])
    const tLocations = Math.min(...target.locations)
    console.log(reduceLocations, 'reduceLocations')
    console.log(newLocations, 'newLocations')
    console.log(tLocations, 'tLocations')
    console.log(
      Math.min(...reduceLocations, ...newLocations, tLocations),
      '===='
    )
    const isMin =
      Math.min(...reduceLocations, ...newLocations, tLocations) === tLocations
    if (!isMin) {
      reduceArr.push(target)
    }
    if (isMin) {
      resArr.push({
        circle: curCircle,
        location: Math.min(...target.locations)
      })
    }
    if (!newArr.length && reduceArr.length) {
      curCircle++
      newArr = reduceArr
      reduceArr = []
    }
  }
  console.log(resArr)
}

getCircle(data)
